﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using élénkPróbája.extentions;
using élénkPróbája.results;
using élénkPróbája.Test.extention;
using élénkPróbája.validators;

namespace élénkPróbája.Test
{
    [TestClass]
    public class InlineValidatorTester
    {
        [TestMethod]
        public void Uses_inline_validator_to_build_rules()
        {
            var cust = new Customer();
            var result = cust.Validate();

            result.Errors.Count.ShouldEqual(2);
        }

        public class Customer
        {
            public int Id { get; set; }
            public string Name { get; set; }

            public ValidationResult Validate()
            {
                return Validator.Validate(this);
            }

            public static readonly InlineValidator<Customer> Validator = new InlineValidator<Customer>()
            {
                v => v.RuleFor(x => x.Name).NotNull(),
                v => v.RuleFor(x => x.Id).NotEqual(0)
            };
        }
    }
}
